package com.woniuxy.mesboot.controller;

import com.woniuxy.mesboot.entity.EmpJob;
import com.woniuxy.mesboot.service.EmpJobService;
import com.woniuxy.mesboot.util.Result;
import com.woniuxy.mesboot.vo.EmpJobVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ：lisir
 * @date ：Created in 2023/5/27 11:14
 * @description：TODO
 */
@RestController
@RequestMapping("/empjobs")
@Slf4j
public class EmpJobController {

    @Resource
    private EmpJobService empJobService;

    @PostMapping
    public Result add(@RequestBody EmpJob empJob) {
        empJobService.insertSelective(empJob);
        return Result.ok();
    }

    @DeleteMapping("{id}")
    public Result delete(@PathVariable Long id) {
        empJobService.deleteByPrimaryKey(id);
        return Result.ok();
    }

    @PutMapping
    public Result update(@RequestBody EmpJob empJob) {
        empJobService.updateByPrimaryKeySelective(empJob);
        return Result.ok();
    }

    @GetMapping("{id}")
    public Result queryById(@PathVariable Long id) {
        EmpJobVO empJobVO = empJobService.selectByPrimaryKey(id);
        if (empJobVO != null) {
            return Result.ok().data("empJob",empJobVO);
        } else {
            return Result.error("暂无数据");
        }
    }

    @GetMapping
    public Result queryAll() {
        List<EmpJobVO> empJobVOS = empJobService.selectAll();
        return Result.ok().data("list",empJobVOS);
    }
}
